package realm.inorder.itmill.ui.panel.logged;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import realm.inorder.itmill.components.InitializableView;
import realm.inorder.itmill.ui.menu.MenuBuilder;
import realm.inorder.itmill.ui.menu.MenuPanel;

import com.itmill.toolkit.ui.GridLayout;

@Component
public class LoggedLayout extends GridLayout implements InitializableView, InitializingBean {

	@Autowired
	private MenuPanel menuPanel;
	
	private com.itmill.toolkit.ui.Component contentPanel; 
	
	public LoggedLayout() {
		super(2, 1);
	}

	public void afterPropertiesSet() throws Exception {
		initComponents();
	}
	
	public void initComponents() {
		this.addComponent(menuPanel);
	}
	
	public void changeContentPanel(com.itmill.toolkit.ui.Component component) {
		if (component == null) {
			return;
		}
		if (contentPanel != null) {
			this.removeComponent(contentPanel);
		}
		contentPanel = component;
		this.addComponent(contentPanel);
		buildMenu();
	}
	
	public void buildMenu() {
		
		if (contentPanel instanceof MenuBuilder) {
			((MenuBuilder)contentPanel).makeMenu(menuPanel);
		}
		
		menuPanel.buildMenu();
	}
	
	public void clearComponents() {
		// TODO Auto-generated method stub
		
	}

	public void initActions() {
		// TODO Auto-generated method stub
		
	}

	public void validateComponents() throws Exception {
		// TODO Auto-generated method stub
		
	}
	
}
